﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EClinic.pathwaysView
{
    public enum PathWayNodesTybes
    {
        StartNode,
        ActivityNode,
        YesOrNoQNode,
        MultiQNode,
        PathWayNode,
        EndNode

    }
    public partial class PathWayDrawing : UserControl
    {
        private Graphics gra;
        public PathWayDrawing()
        {
            InitializeComponent();
            
        }
        
        public List<Point> DrawPoints = new List<Point>();

        public void DrawNode(Point Postion, PathWayNodesTybes tybe)
        {
            if (tybe == PathWayNodesTybes.StartNode)
            {
                EClinic.pathwaysView.Nodes.StartNode startnode=new Nodes.StartNode();

                startnode.Location = new Point(Postion.X - startnode.Size.Height / 2, Postion.Y - startnode.Size.Width / 2);

                startnode.CreateControl();

                this.Controls.Add(startnode);
                //draw start node in postion 
            }
            else if (tybe==PathWayNodesTybes.ActivityNode)
            {
                EClinic.pathwaysView.Nodes.ActivityNode activity_node = new Nodes.ActivityNode();
                activity_node.Location = new Point(Postion.X - activity_node.Size.Height / 2, Postion.Y - activity_node.Size.Width / 2);
                activity_node.CreateControl();
                this.Controls.Add(activity_node);
                
            }
            else if (tybe== PathWayNodesTybes.YesOrNoQNode)
            {
                EClinic.pathwaysView.Nodes.YesOrNoQNode yes_no = new Nodes.YesOrNoQNode();
              
                yes_no.CreateControl();
                yes_no.Location = new Point(Postion.X - yes_no.Size.Height / 2, Postion.Y - yes_no.Size.Width / 2);
                this.Controls.Add(yes_no);
            }
            else if (tybe==PathWayNodesTybes.MultiQNode)
            {
                EClinic.pathwaysView.Nodes.MultiQNode multiqnode = new Nodes.MultiQNode();
                multiqnode.Location = new Point(Postion.X - multiqnode.Size.Height / 2, Postion.Y - multiqnode.Size.Width / 2);
                multiqnode.CreateControl();
                this.Controls.Add(multiqnode);
            }
            else if (tybe==PathWayNodesTybes.PathWayNode)
            {
                EClinic.pathwaysView.Nodes.PathWayNode pathwaynode = new Nodes.PathWayNode();
                pathwaynode.Location = new Point(Postion.X - pathwaynode.Size.Height / 2, Postion.Y - pathwaynode.Size.Width / 2);
                pathwaynode.CreateControl();
                this.Controls.Add(pathwaynode);
            }
            else if (tybe == PathWayNodesTybes.EndNode)
            {
                EClinic.pathwaysView.Nodes.EndNode endnode = new Nodes.EndNode();
                endnode.Location = new Point(Postion.X - endnode.Size.Height / 2, Postion.Y - endnode.Size.Width / 2);
                endnode.CreateControl();
                this.Controls.Add(endnode);
                //draw End node in postion 
            }
            
        }

        private void PathWayDrawing_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetData(DataFormats.Text).ToString() == "Activtynode" || e.Data.GetData(DataFormats.Text).ToString() == "MQN" || e.Data.GetData(DataFormats.Text).ToString() == "YsNoNode")
            {

                 e.Effect = DragDropEffects.Copy;  
          
            }
            
        }

        private void PathWayDrawing_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetData(DataFormats.Text).ToString() == "Activtynode")
            {
                Point clientPosition = this.PointToClient(System.Windows.Forms.Cursor.Position);
                
                DrawNode(clientPosition, PathWayNodesTybes.ActivityNode);
            } if (e.Data.GetData(DataFormats.Text).ToString() == "MQN")
            {
                Point clientPosition = this.PointToClient(System.Windows.Forms.Cursor.Position);

                DrawNode(clientPosition, PathWayNodesTybes.MultiQNode);
            } if (e.Data.GetData(DataFormats.Text).ToString() == "YsNoNode")
            {
                Point clientPosition = this.PointToClient(System.Windows.Forms.Cursor.Position);

                DrawNode(clientPosition, PathWayNodesTybes.YesOrNoQNode);
            }

        }

        private void PathWayDrawing_Load(object sender, EventArgs e)
        {

        }

        private void PathWayDrawing_MouseMove(object sender, MouseEventArgs e)
        {
            pathwaysView.Relation.TempEndpoint = e.Location;
            Invalidate();
        }

        private void PathWayDrawing_Paint(object sender, PaintEventArgs e)
        {
          gra=  e.Graphics ;
            gra.DrawLine(Pens.Red, pathwaysView.Relation.TempStartpoint, pathwaysView.Relation.TempEndpoint);
        }


    }
}
